package com.tiancheng.trade.authserver.component.login.impl;


import com.tiancheng.trade.authserver.component.login.BaseUserLoginHandler;
import com.tiancheng.trade.authserver.entity.AuthUser;
import com.tiancheng.trade.authserver.enums.LogInTypeEnum;
import com.tiancheng.trade.authserver.service.IAuthUserService;
import com.tiancheng.trade.authserver.service.ITencentCaptchaService;
import com.tiancheng.trade.authserver.vo.UserLoginInVO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 短信验证码登录
 */
@Component("smsCodeLoginHandler")
public class SmsCodeLoginHandler extends BaseUserLoginHandler {
    @Resource
    protected IAuthUserService userService;
    @Resource
    protected ITencentCaptchaService tencentCaptchaService;

    @Override
    protected void paramValidate(UserLoginInVO param, boolean checkCertificate) {
//        if (checkCertificate) {
//            this.tencentCaptchaService.verification(param.getValidate());
//        }
//        String phone = param.getPhone();
//        Assert.isNotEmpty(phone,
//                ErrorCodeConstant.auth_phoneIsNull,
//                MessageSourceUtils.getMessage(ErrorCodeConstant.auth_phoneIsNull));
//        param.setTokenType(Token.TokenType.web_phone);
//        param.setThirdPlatform(ThirdPlatform.tengyun);
//        param.setClientId(this.tengyunRequestProperties.getClientId());
    }

    @Override
    protected AuthUser getUserByParam(UserLoginInVO param, boolean checkCertificate) {
        if (checkCertificate) {
            //this.captchaService.verificationSignInCode(param.getEmail(), param.getPhone(), param.getCode());
        }
        String phone = param.getPhone();
        AuthUser user = this.userService.getByPhone(phone);
        return user;
    }


    @Override
    public LogInTypeEnum getHandleType() {
        return LogInTypeEnum.SmsCode;
    }
}
